'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 2_study_chat_model_out_stream.py
* @Time: 2025/7/10
* @All Rights Reserve By Brtc
'''
from datetime import datetime

import dotenv
from langchain_community.chat_models import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

dotenv.load_dotenv()
prompt = ChatPromptTemplate.from_messages([
    ("system", "你是OpenAI开发的机器人， 请根据用户的问题回复， 现在的时间是{now}"),
    ("human", "{query}")
]).partial(now=datetime.now())

# 创建大模型
llm = ChatOpenAI(model = "gpt-3.5-turbo")
ai_meaasge = llm.stream(prompt.invoke({"query":"现在几点钟了, 最近我在学习langchain 请给一点学习建议，300字左右"}))
for chunk in  ai_meaasge:
    print(chunk.content, flush=True, end="")

